/****************************************/
function Selects(matchString){ 
	this.matchString=matchString; 
	this.options=new Array(); 
	this.curoptions=new Array();  
	this.reflash=SelectReflash;		
	this.SelectInit=SelectInit;		
	this.addOption=addOption;		
	this.UMatchString=updateMatchString;
} 

function OptionItem(_Code,_Name,_MaxNum,_MinNum,_Scale,_BuziName){
	this._Code=_Code;				
	this._Name=_Name;				
	this._MaxNum=_MaxNum;				
	this._MinNum=_MinNum;				
	this._Scale=_Scale;					
	this._BuziName=_BuziName;				
} 
function addOption(_Code,_Name,_MaxNum,_MinNum,_Scale,_BuziName){
	this.options.push(new OptionItem(_Code,_Name,_MaxNum,_MinNum,_Scale,_BuziName));	
}
function updateMatchString(matchString){
	this.matchString=matchString;
	this.reflash();
}
function SelectInit(){  
	var	mS = new RegExp(this.matchString,"i"); 
	this.curoptions=new Array();  
	for (var i=0;i<this.options.length;i++){
		var pushflag=false;
		if (this.matchString!=null||this.matchString!=''){  
			if (this.options[i]._BuziName==this.matchString)
				pushflag=true;
		}  
		if (pushflag){ 
			this.curoptions.push(this.options[i]); 
			}
	}
}
function SelectReflash(){    
	this.SelectInit();  
	clearBuziRow(buzibody);
	for (var i=0;i<this.curoptions.length;i++){
		//if (i>5)
		//	return;
		optionitem=this.curoptions[i]; 
		addBuziRow(buzibody,optionitem); 
	} 
}
/******************************/
function addBuziRow(obj,optionitem){
	var row=obj.insertRow();
	buildRow(row,optionitem);
	
}
function clearBuziRow(obj){
	var i=0;
	while (obj.rows.length>0) {
	obj.deleteRow(i);
	}
	
	//buzibody.deleteRow ();
	
}
function buildRow(row,optionitem){
	
	 row.insertCell(0).innerHTML=optionitem._Name; 
	 var values=optionitem._Scale;
	 if (values=='null'||values==null){
		values='0';
	 }
	 row.insertCell(1).innerHTML=values;
	 values=optionitem._MinNum;
	 if (values=='null'||values==null){
		values='0';
	 }
	 row.insertCell(2).innerHTML=values;
	 values=optionitem._MaxNum;
	 if (values=='null'||values==null){
		values='0';
	 }
	 row.insertCell(3).innerHTML=values;
	 var str='<img align="absbottom" style="cursor:hand" id="'+optionitem._Code+'" onclick="javascript:busitypeadd(this.id)"  src="/image/kx_new.gif" border="0"/>';
	 row.insertCell(4).innerHTML=str;
}
function busitypeadd(_Code){ 
	var objnum=eval('document.all("'+_Code+'_num")'); 
	 
	busitypeadditem(objnum,_Code);
}
function busitypeoperitem(obj,max,min,count){
	var curnum=parseInt(obj.value);
	curnum+=count;
	 busitypesetitem(obj,max,min,curnum)
}
function busitypesetitem(obj,max,min,num){
	var curnum=num; 
	if(max==null||max=='null')
		max=10;
	if(min==null||min=='null')
		min=1; 
	if (parseInt(curnum)>parseInt(max)){ 
		overNum();
		obj.focus();
		obj.value=max;
		return; 
	}
	if (parseInt(curnum)<parseInt(min)){ 
		overNum();
		obj.focus();
		obj.value=min;
		return; 
	}
	obj.value=curnum;
}
function busitypeadditem(objnum,_Code){
	for (var i=0;i<buzicontant.options.length;i++){
		var curoption=buzicontant.options[i];
		if (curoption._Code==_Code){
			if (objnum==null){
			 var row=buzibodyed.insertRow();   
			 row.insertCell(0).innerHTML=curoption._Name;  
			 row.insertCell(1).innerHTML=curoption._Scale;  
			 var str='<a style="cursor:hand" onclick="javascript:operbusi(\''+_Code+'\',-1)"><<</a>';
			 str+='<input value="'+curoption._MinNum+'" onblur="javascript:setbusi(\''+_Code+'\',this.value)" name="'+_Code+'_num" id="'+_Code+'_num" size="2">';
			 str+='<a style="cursor:hand" onclick="javascript:operbusi(\''+_Code+'\',+1)">>></a>';
			 row.insertCell(2).innerHTML=str;
			 row.insertCell(3).innerHTML='<a style="cursor:hand" onclick="javascript:delebusi(this)">'+delstr+'</a>'; 			 
			 }else{
			 	busitypeoperitem(objnum,curoption._MaxNum,curoption._MinNum,1);
			 }
			 return;
		}
		
		
	}
}
function busitypeinit(num,_Code){
	for (var i=0;i<buzicontant.options.length;i++){
		var curoption=buzicontant.options[i];
		if (curoption._Code==_Code){ 
			 var row=buzibodyed.insertRow();   
			 row.insertCell(0).innerHTML=curoption._Name; 
			 row.insertCell(1).innerHTML=curoption._Scale;   
			 var str='<a style="cursor:hand" onclick="javascript:operbusi(\''+_Code+'\',-1)"><<</a>';
			 str+='<input value="'+num+'" onblur="javascript:setbusi(\''+_Code+'\',this.value)" name="'+_Code+'_num" id="'+_Code+'_num" size="2">';
			 str+='<a style="cursor:hand" onclick="javascript:operbusi(\''+_Code+'\',+1)">>></a>';
			 row.insertCell(2).innerHTML=str;
			 row.insertCell(3).innerHTML='<a style="cursor:hand" onclick="javascript:delebusi(this)">'+delstr+'</a>'; 
			 
		}
		
		
	}
}
function operbusi(_Code,count){  
	for (var i=0;i<buzicontant.options.length;i++){
		var curoption=buzicontant.options[i];
		if (curoption._Code==_Code){ 
			var objnum=eval('document.all("'+_Code+'_num")');
		 	busitypeoperitem(objnum,curoption._MaxNum,curoption._MinNum,count);
		 	return;
		}
		
	}
}
function delebusi(obj){   
	for (var i=0;i<buzibodyed.rows.length;i++){
		if(buzibodyed.rows(i).cells(3)==obj.parentNode){		
			buzibodyed.deleteRow(i);
			return ;
		}
	}
}
function setbusi(_Code,num){ 
 
	for (var i=0;i<buzicontant.options.length;i++){
		var curoption=buzicontant.options[i];
		if (curoption._Code==_Code){ 
			var objnum=eval('document.all("'+_Code+'_num")');
		 	busitypesetitem(objnum,curoption._MaxNum,curoption._MinNum,num);
		 	return;
		}
		
	}
}
function setBusiOK(obj){
	clearBuziRow(obj);
	opener.cleanBuzi(); 
	//alert(opener.document.all('businums').value);
	//parent.document.all('telecomBuziTypes').value='';
	for (var i=0;i<buzicontant.options.length;i++){
		var curoption=buzicontant.options[i];
		var objnum=eval('document.all("'+curoption._Code+'_num")'); 
		if (objnum!=null){
			setBusiOKRow(obj,curoption,objnum.value);
		}
		
	}
}
function setBusiOKRow(obj,curoption,num){
	setBusiOKRowDetail(obj,curoption._Code,curoption._Scale,curoption._Name,num); 
}
function setBusiOKRowDetail(obj,code,scale,name,num){ 
	 var row=obj.insertRow();  
	 var str='<input name="busicode" type="hidden" value="'+code+'">';
	 var cell=row.insertCell(0);
	 cell.innerHTML=str+name;   
	  str='<input name="businum" type="hidden" value="'+num+'">'
	 cell.bgColor='white';
	  cell=row.insertCell(1);
	 cell.innerHTML=scale;
	 cell.bgColor='white';
	  cell=row.insertCell(2);
	 cell.innerHTML=str+num;
	 cell.bgColor='white';
	 
	opener.addBuzi(code,num); 
} 
function setBusiOKRowDetailself(obj,code,scale,name,num){ 
	 var row=obj.insertRow();  
	 var str='<input name="busicode" type="hidden" value="'+code+'">';
	 var cell=row.insertCell(0);
	 cell.innerHTML=str+name;   
	 str='<input name="businum" type="hidden" value="'+num+'">';
	 cell.bgColor='white';
	  cell=row.insertCell(1);
	 cell.innerHTML=scale;
	 cell.bgColor='white';
	  cell=row.insertCell(2);
	 cell.innerHTML=str+num;
	 cell.bgColor='white';
	addBuzi(code,num,scale); 
} 
function init(){
	var obj=window.opener.document.all('busicode');
	var objnum=window.opener.document.all('businum');
	if (obj!=null){ 
		for (var i=0;i<obj.length;i++){
			var code=obj[i].value;
			var num=objnum[i].value;
			busitypeinit(num,code);
		}
	} 
}






